//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS RDSData service.
///
/// RDS Data API Amazon RDS provides an HTTP endpoint to run SQL statements on an Amazon Aurora DB cluster. To run these statements, you use the RDS Data API (Data API). Data API is available with the following types of Aurora databases:   Aurora PostgreSQL - Serverless v2, provisioned, and Serverless v1   Aurora MySQL - Serverless v2, provisioned, and Serverless v1   For more information about the Data API, see Using RDS Data API in the Amazon Aurora User Guide.
public struct RDSData: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the RDSData client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "RDSData",
            serviceIdentifier: "rds-data",
            serviceProtocol: .restjson,
            apiVersion: "2018-08-01",
            endpoint: endpoint,
            variantEndpoints: Self.variantEndpoints,
            errorType: RDSDataErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }




    /// FIPS and dualstack endpoints
    static var variantEndpoints: [EndpointVariantType: AWSServiceConfig.EndpointVariant] {[
        [.fips]: .init(endpoints: [
            "us-east-1": "rds-data-fips.us-east-1.amazonaws.com",
            "us-east-2": "rds-data-fips.us-east-2.amazonaws.com",
            "us-west-1": "rds-data-fips.us-west-1.amazonaws.com",
            "us-west-2": "rds-data-fips.us-west-2.amazonaws.com"
        ])
    ]}

    // MARK: API Calls

    /// Runs a batch SQL statement over an array of data. You can run bulk update and insert operations for multiple records using a DML  statement with different parameter sets. Bulk operations can provide a significant  performance improvement over individual insert and update operations.  If a call isn't part of a transaction because it doesn't include the transactionID parameter, changes that result from the call are committed automatically. There isn't a fixed upper limit on the number of parameter sets. However, the maximum size of the HTTP request submitted through the Data API is 4 MiB. If the request exceeds this limit, the Data API returns an error and doesn't process the request. This 4-MiB limit includes the size of the HTTP headers and the JSON notation in the request. Thus, the number of parameter sets that you can include depends on a combination of factors, such as the size of the SQL statement and the size of each parameter set. The response size limit is 1 MiB. If the call returns more than 1 MiB of response data, the call is terminated.
    @Sendable
    @inlinable
    public func batchExecuteStatement(_ input: BatchExecuteStatementRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> BatchExecuteStatementResponse {
        try await self.client.execute(
            operation: "BatchExecuteStatement", 
            path: "/BatchExecute", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Runs a batch SQL statement over an array of data. You can run bulk update and insert operations for multiple records using a DML  statement with different parameter sets. Bulk operations can provide a significant  performance improvement over individual insert and update operations.  If a call isn't part of a transaction because it doesn't include the transactionID parameter, changes that result from the call are committed automatically. There isn't a fixed upper limit on the number of parameter sets. However, the maximum size of the HTTP request submitted through the Data API is 4 MiB. If the request exceeds this limit, the Data API returns an error and doesn't process the request. This 4-MiB limit includes the size of the HTTP headers and the JSON notation in the request. Thus, the number of parameter sets that you can include depends on a combination of factors, such as the size of the SQL statement and the size of each parameter set. The response size limit is 1 MiB. If the call returns more than 1 MiB of response data, the call is terminated.
    ///
    /// Parameters:
    ///   - database: The name of the database.
    ///   - parameterSets: The parameter set for the batch operation. The SQL statement is executed as many times as the number of parameter sets provided.  To execute a SQL statement with no parameters, use one of the following options:   Specify one or more empty parameter sets.   Use the ExecuteStatement operation instead of the BatchExecuteStatement operation.    Array parameters are not supported.
    ///   - resourceArn: The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    ///   - schema: The name of the database schema.  Currently, the schema parameter isn't supported.
    ///   - secretArn: The ARN of the secret that enables access to the DB cluster. Enter the database user name and password for the credentials in the secret. For information about creating the secret, see Create a database secret.
    ///   - sql: The SQL statement to run. Don't include a semicolon (;) at the end of the SQL statement.
    ///   - transactionId: The identifier of a transaction that was started by using the BeginTransaction operation. Specify the transaction ID of the transaction that you want to include the SQL statement in. If the SQL statement is not part of a transaction, don't set this parameter.
    ///   - logger: Logger use during operation
    @inlinable
    public func batchExecuteStatement(
        database: String? = nil,
        parameterSets: [[SqlParameter]]? = nil,
        resourceArn: String,
        schema: String? = nil,
        secretArn: String,
        sql: String,
        transactionId: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> BatchExecuteStatementResponse {
        let input = BatchExecuteStatementRequest(
            database: database, 
            parameterSets: parameterSets, 
            resourceArn: resourceArn, 
            schema: schema, 
            secretArn: secretArn, 
            sql: sql, 
            transactionId: transactionId
        )
        return try await self.batchExecuteStatement(input, logger: logger)
    }

    /// Starts a SQL transaction.  A transaction can run for a maximum of 24 hours. A transaction is terminated and rolled back automatically after 24 hours. A transaction times out if no calls use its transaction ID in three minutes. If a transaction times out before it's committed, it's rolled back automatically. For Aurora MySQL, DDL statements inside a transaction cause an implicit commit. We recommend that you run each MySQL DDL statement in a separate ExecuteStatement call with continueAfterTimeout enabled.
    @Sendable
    @inlinable
    public func beginTransaction(_ input: BeginTransactionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> BeginTransactionResponse {
        try await self.client.execute(
            operation: "BeginTransaction", 
            path: "/BeginTransaction", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Starts a SQL transaction.  A transaction can run for a maximum of 24 hours. A transaction is terminated and rolled back automatically after 24 hours. A transaction times out if no calls use its transaction ID in three minutes. If a transaction times out before it's committed, it's rolled back automatically. For Aurora MySQL, DDL statements inside a transaction cause an implicit commit. We recommend that you run each MySQL DDL statement in a separate ExecuteStatement call with continueAfterTimeout enabled.
    ///
    /// Parameters:
    ///   - database: The name of the database.
    ///   - resourceArn: The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    ///   - schema: The name of the database schema.
    ///   - secretArn: The name or ARN of the secret that enables access to the DB cluster.
    ///   - logger: Logger use during operation
    @inlinable
    public func beginTransaction(
        database: String? = nil,
        resourceArn: String,
        schema: String? = nil,
        secretArn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> BeginTransactionResponse {
        let input = BeginTransactionRequest(
            database: database, 
            resourceArn: resourceArn, 
            schema: schema, 
            secretArn: secretArn
        )
        return try await self.beginTransaction(input, logger: logger)
    }

    /// Ends a SQL transaction started with the BeginTransaction operation and commits the changes.
    @Sendable
    @inlinable
    public func commitTransaction(_ input: CommitTransactionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> CommitTransactionResponse {
        try await self.client.execute(
            operation: "CommitTransaction", 
            path: "/CommitTransaction", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Ends a SQL transaction started with the BeginTransaction operation and commits the changes.
    ///
    /// Parameters:
    ///   - resourceArn: The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    ///   - secretArn: The name or ARN of the secret that enables access to the DB cluster.
    ///   - transactionId: The identifier of the transaction to end and commit.
    ///   - logger: Logger use during operation
    @inlinable
    public func commitTransaction(
        resourceArn: String,
        secretArn: String,
        transactionId: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> CommitTransactionResponse {
        let input = CommitTransactionRequest(
            resourceArn: resourceArn, 
            secretArn: secretArn, 
            transactionId: transactionId
        )
        return try await self.commitTransaction(input, logger: logger)
    }

    /// Runs one or more SQL statements.  This operation isn't supported for Aurora Serverless v2 and provisioned DB clusters. For Aurora Serverless v1 DB clusters, the operation is deprecated. Use the BatchExecuteStatement or ExecuteStatement operation.
    @available(*, deprecated, message: "The ExecuteSql API is deprecated, please use the ExecuteStatement API.")
    @Sendable
    @inlinable
    public func executeSql(_ input: ExecuteSqlRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ExecuteSqlResponse {
        try await self.client.execute(
            operation: "ExecuteSql", 
            path: "/ExecuteSql", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Runs one or more SQL statements.  This operation isn't supported for Aurora Serverless v2 and provisioned DB clusters. For Aurora Serverless v1 DB clusters, the operation is deprecated. Use the BatchExecuteStatement or ExecuteStatement operation.
    ///
    /// Parameters:
    ///   - awsSecretStoreArn: The Amazon Resource Name (ARN) of the secret that enables access to the DB cluster. Enter the database user name and password for the credentials in the secret. For information about creating the secret, see Create a database secret.
    ///   - database: The name of the database.
    ///   - dbClusterOrInstanceArn: The ARN of the Aurora Serverless DB cluster.
    ///   - schema: The name of the database schema.
    ///   - sqlStatements: One or more SQL statements to run on the DB cluster. You can separate SQL statements from each other with a semicolon (;). Any valid SQL statement is permitted, including data definition, data manipulation, and commit statements.
    ///   - logger: Logger use during operation
    @available(*, deprecated, message: "The ExecuteSql API is deprecated, please use the ExecuteStatement API.")
    @inlinable
    public func executeSql(
        awsSecretStoreArn: String,
        database: String? = nil,
        dbClusterOrInstanceArn: String,
        schema: String? = nil,
        sqlStatements: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ExecuteSqlResponse {
        let input = ExecuteSqlRequest(
            awsSecretStoreArn: awsSecretStoreArn, 
            database: database, 
            dbClusterOrInstanceArn: dbClusterOrInstanceArn, 
            schema: schema, 
            sqlStatements: sqlStatements
        )
        return try await self.executeSql(input, logger: logger)
    }

    /// Runs a SQL statement against a database.  If a call isn't part of a transaction because it doesn't include the transactionID parameter, changes that result from the call are committed automatically. If the binary response data from the database is more than 1 MB, the call is terminated.
    @Sendable
    @inlinable
    public func executeStatement(_ input: ExecuteStatementRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ExecuteStatementResponse {
        try await self.client.execute(
            operation: "ExecuteStatement", 
            path: "/Execute", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Runs a SQL statement against a database.  If a call isn't part of a transaction because it doesn't include the transactionID parameter, changes that result from the call are committed automatically. If the binary response data from the database is more than 1 MB, the call is terminated.
    ///
    /// Parameters:
    ///   - continueAfterTimeout: A value that indicates whether to continue running the statement after  the call times out. By default, the statement stops running when the call  times out.  For DDL statements, we recommend continuing to run the statement after  the call times out. When a DDL statement terminates before it is finished  running, it can result in errors and possibly corrupted data structures.
    ///   - database: The name of the database.
    ///   - formatRecordsAs: A value that indicates whether to format the result set as a single JSON string. This parameter only applies to SELECT statements and is ignored for other types of statements. Allowed values are NONE and JSON. The default value is NONE. The result is returned in the formattedRecords field. For usage information about the JSON format for result sets, see Using the Data API in the Amazon Aurora User Guide.
    ///   - includeResultMetadata: A value that indicates whether to include metadata in the results.
    ///   - parameters: The parameters for the SQL statement.  Array parameters are not supported.
    ///   - resourceArn: The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    ///   - resultSetOptions: Options that control how the result set is returned.
    ///   - schema: The name of the database schema.  Currently, the schema parameter isn't supported.
    ///   - secretArn: The ARN of the secret that enables access to the DB cluster. Enter the database user name and password for the credentials in the secret. For information about creating the secret, see Create a database secret.
    ///   - sql: The SQL statement to run.
    ///   - transactionId: The identifier of a transaction that was started by using the BeginTransaction operation. Specify the transaction ID of the transaction that you want to include the SQL statement in. If the SQL statement is not part of a transaction, don't set this parameter.
    ///   - logger: Logger use during operation
    @inlinable
    public func executeStatement(
        continueAfterTimeout: Bool? = nil,
        database: String? = nil,
        formatRecordsAs: RecordsFormatType? = nil,
        includeResultMetadata: Bool? = nil,
        parameters: [SqlParameter]? = nil,
        resourceArn: String,
        resultSetOptions: ResultSetOptions? = nil,
        schema: String? = nil,
        secretArn: String,
        sql: String,
        transactionId: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ExecuteStatementResponse {
        let input = ExecuteStatementRequest(
            continueAfterTimeout: continueAfterTimeout, 
            database: database, 
            formatRecordsAs: formatRecordsAs, 
            includeResultMetadata: includeResultMetadata, 
            parameters: parameters, 
            resourceArn: resourceArn, 
            resultSetOptions: resultSetOptions, 
            schema: schema, 
            secretArn: secretArn, 
            sql: sql, 
            transactionId: transactionId
        )
        return try await self.executeStatement(input, logger: logger)
    }

    /// Performs a rollback of a transaction. Rolling back a transaction cancels its changes.
    @Sendable
    @inlinable
    public func rollbackTransaction(_ input: RollbackTransactionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> RollbackTransactionResponse {
        try await self.client.execute(
            operation: "RollbackTransaction", 
            path: "/RollbackTransaction", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Performs a rollback of a transaction. Rolling back a transaction cancels its changes.
    ///
    /// Parameters:
    ///   - resourceArn: The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    ///   - secretArn: The name or ARN of the secret that enables access to the DB cluster.
    ///   - transactionId: The identifier of the transaction to roll back.
    ///   - logger: Logger use during operation
    @inlinable
    public func rollbackTransaction(
        resourceArn: String,
        secretArn: String,
        transactionId: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> RollbackTransactionResponse {
        let input = RollbackTransactionRequest(
            resourceArn: resourceArn, 
            secretArn: secretArn, 
            transactionId: transactionId
        )
        return try await self.rollbackTransaction(input, logger: logger)
    }
}

extension RDSData {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: RDSData, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}
